package cn.edu.service.impl;

import cn.edu.dao.lead_TeacherDao;
import cn.edu.domain.All;
import cn.edu.domain.PageBean;
import cn.edu.service.lead_TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Davey chan
 */
@Service
public  class lead_TeacherServiceImpl implements lead_TeacherService {
    @Autowired
    private lead_TeacherDao teacherDao;
    @Override
    public PageBean<All> selectByPageAndcondition(int currentPage, int pageSize, All t) {

        int begin=(currentPage-1)*pageSize;
//        计算查询的条目数
        int size =pageSize;
//        处理查询条件，模糊查询
        String teacherName = t.getTeacherName();
        if(teacherName !=null && teacherName.length()>0){
            t.setTeacherName("%"+teacherName+"%");
        }
        String title = t.getTitle();
        if(title !=null && title.length()>0){
            t.setTitle("%"+title+"%");

        }

        String academyName = t.getAcademyName();
        if(academyName!=null && academyName.length()>0){
            t.setAcademyName("%"+academyName+"%");

        }
        String departmentName = t.getDepartmentName();
        if(departmentName!=null && departmentName.length()>0){
            t.setDepartmentName("%"+departmentName+"%");

        }
        String tutor = t.getTutor();
        if(tutor!=null && tutor.length()>0){
            t.setTutor("%"+tutor+"%");

        }
        String polstatus = t.getPolstatus();
        if(polstatus!=null && polstatus.length()>0){
            t.setPolstatus("%"+polstatus+"%");

        }
        t.setExamstatus("3");



        List<All> rows = teacherDao.selectBypageAndCondtion(begin, size,t);
//        查询总记录数
        int totalCount = teacherDao.selectTotalCountByCondition(t);
//封装pageBean

        PageBean<All> pageBean=new PageBean<>();
        pageBean.setRows(rows);
        pageBean.setTotalCount(totalCount);


        return pageBean;
    }


}
